#include "DataManager.h"
#include <QVariant>
#include <QDebug>

DataManager::DataManager()
{
}

bool DataManager::initialize(QString driver, QString host, QString dbName, QString uName, QString pass, int port)
{
    m_db = QSqlDatabase::addDatabase(driver);
    m_db.setHostName(host);
    m_db.setPort(port);
    m_db.setDatabaseName(dbName);
    m_db.setUserName(uName);
    m_db.setPassword(pass);
    return m_db.open();
}

void DataManager::setQuery(QString query)
{
    m_query = QSqlQuery(query, m_db);
}

bool DataManager::next()
{
    return m_query.next();
}

QString DataManager::getNext()
{
    return m_query.value(0).toString();
}

bool DataManager::prepareQuery(QString query)
{
    return m_query.prepare(query);
}

bool DataManager::execQuery()
{
    return m_query.exec();
}
